﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Collections;
using ERMap;

namespace PhoneBook.Group
{
    public class Group
    {
        public static Hashtable get(string groupid)
        {
            Hashtable keys = new Hashtable();
            keys.Add("groupid", groupid);
            return ERMapHelper.getmodel("b_group", keys);
        }

        public static Hashtable getanymodel(string groupid)
        {
            Hashtable keys = new Hashtable();
            keys.Add("groupid", groupid);
            return ERMapHelper.getCustomModel("select * from b_group where 1=1 ", keys);
        }

        public static void del(string groupid)
        {
            Hashtable keys = new Hashtable();
            keys["groupid"] = groupid;
            ERMapHelper.delmodel("b_group", keys);
        }

        public static DataSet query_isopen(string groupname)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select * from b_group ");
            sb.Append(" where groupname like @groupname and  isnull(isdel,0)<>1 ");//and groupid in(select groupid from b_phonebook where isnull(isdel,0)<>1 )

            Hashtable keys = new Hashtable();
            keys["groupname"] = "%"+groupname+"%";

            return ERMapHelper.getCustomData(sb.ToString(), keys);
        }

        public static DataSet query_phonebook(string groupname)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("select g.groupname,pb.phonebookname,be.* from b_group g  ");
            sb.Append("inner join b_phonebook pb on g.groupid=pb.groupid  ");
            sb.Append("inner join b_pbmember pm on pm.phonebookid=pb.phonebookid  ");
            sb.Append("inner join b_employee be on be.employeeid=pm.memberid  ");
            //sb.Append("where g.groupname like @groupname  ");
            sb.Append("where ");
            //sb.Append("and  isnull(g.isdel,0)<>1   ");
            sb.Append(" isnull(g.isdel,0)<>1   ");
            sb.Append("and  isnull(pb.isdel,0)<>1   ");
            sb.Append("and  isnull(pm.isdel,0)<>1   ");
            sb.Append("and  isnull(be.isdel,0)<>1   ");
            Hashtable keys = new Hashtable();
            keys["groupname"] = "%" + groupname + "%";

            return ERMapHelper.getCustomData(sb.ToString(), keys);
        }
    }
}
